package cn.wolfcode.wolf2w.service.impl;


import cn.wolfcode.wolf2w.domain.UserView;
import cn.wolfcode.wolf2w.redis.service.IUserViewRedisService;
import cn.wolfcode.wolf2w.repository.UserViewRepository;
import cn.wolfcode.wolf2w.service.IUserViewService;
import cn.wolfcode.wolf2w.vo.UserViewVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class UserViewServiceImpl implements IUserViewService {
    @Autowired
    private UserViewRepository userViewRepository;
    @Autowired
    private IUserViewRedisService userViewRedisService;


    @Override
    public void insert(UserView userView) {
        userViewRepository.save(userView);
    }

    @Override
    public void delete(String id) {
        userViewRepository.deleteById(id);
    }

    @Override
    public void update(UserView userView) {
        userViewRepository.save(userView);
    }

    @Override
    public UserView findById(String id) {
        Optional<UserView> userView = userViewRepository.findById(id);
        return userView.orElse(null);
    }

    @Override
    public List<UserView> findAll() {
        List<UserView> all = userViewRepository.findAll();
        return all;
    }

    @Override
    public UserViewVo find(String ownerId, String uid) {

        UserViewVo userViewVo = userViewRedisService.insert(ownerId, uid);

        return userViewVo;
    }


}
